/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-3-24 下午5:17 Created by dwzhang
 */
package com.jade.bss.crm.impl;

import java.util.Date;
import javax.ejb.TransactionAttribute;
import javax.inject.Inject;
import javax.inject.Named;

import com.jade.bss.base.BssException;
import com.jade.bss.crm.Feedback;
import com.jade.bss.crm.FeedbackDao;
import com.jade.bss.crm.FeedbackManager;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.util.PagingList;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户反馈管理器实现。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-3-24 下午5:17
 */
@Named ("bss_feedbackManager")
public class FeedbackManagerImpl
        implements FeedbackManager
{
    protected FeedbackDao feedbackDao;

    @Inject
    public void setFeedbackDao(@Named ("bss_feedbackDao") FeedbackDao feedbackDao)
    {
        this.feedbackDao = feedbackDao;
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Exception.class)
    public void addFeedback(Feedback feedback)
            throws BssException
    {
        Date now = new Date();
        feedback.setCreationDate(now);
        feedbackDao.addFeedback(feedback);
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Exception.class)
    public void updateFeedback(Feedback feedback)
            throws BssException
    {
        feedbackDao.updateFeedback(feedback);
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Exception.class)
    public void removeFeedback(long... ids)
            throws BssException
    {
        for (long id : ids) {
            Feedback feedback = getFeedback(id);
            if (feedback != null) {
                feedbackDao.removeFeedback(feedback);
            }
        }
    }

    public Feedback getFeedback(long id)
    {
        return feedbackDao.getFeedback(id);
    }

    public PagingList<Feedback> queryFeedback(Criteria criteria)
    {
        return feedbackDao.queryFeedback(criteria);
    }
}
